package com.xfly.app.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.utils.GlideUtil;
import com.ptmall.app.view.TitleBarView;
import com.xfly.app.bean.ShBean;

import java.util.HashMap;
import java.util.Map;

public class ShDetilActivity extends BaseMvpActivity {

    TitleBarView title_bar;

    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();
    ImageView img1,img2;
    String id;
    TextView gs,dz,xx,bhg,tg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_shxq);
    }

    @Override
    public void initViews() {
        id = getIntent().getStringExtra("id");
        title_bar = findViewById(R.id.title_bar);
        img1 = findViewById(R.id.img1);
        img2 = findViewById(R.id.img2);
        gs = findViewById(R.id.gs);
        dz = findViewById(R.id.dz);
        xx = findViewById(R.id.xx);
        bhg = findViewById(R.id.bhg);
        tg = findViewById(R.id.tg);

    }

    @Override
    public void initEvents() {

        bhg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Map<String,String> map = new HashMap<>();
                map.put("apply_id",id);
                map.put("status","1");
                apiDataRepository.clsj(map, new ApiNetResponse<Object>() {
                    @Override
                    public void onSuccess(Object data) {
                        showMsg("操作成功");
                        getData();
                    }
                });
            }
        });

        tg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Map<String,String> map = new HashMap<>();
                map.put("apply_id",id);
                map.put("status","2");
                apiDataRepository.clsj(map, new ApiNetResponse<Object>() {
                    @Override
                    public void onSuccess(Object data) {
                        showMsg("操作成功");
                        getData();
                    }
                });
            }
        });

        title_bar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });
        title_bar.setText("审核详情");
    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    private void getData(){
        Map<String,String> map =new HashMap<>();
        map.put("apply_id",id);
        apiDataRepository.getsh(map, new ApiNetResponse<ShBean>() {
            @Override
            public void onSuccess(ShBean data) {
                GlideUtil.showImg(getContext(),data.idcard,img1);
                GlideUtil.showImg(getContext(),data.license,img2);
                gs.setText(data.company);
                dz.setText(data.province+data.city+data.area);
                xx.setText(data.address);

                switch (data.status){
                    case "0":

                        break;
                    case "1":
                        bhg.setVisibility(View.GONE);
                        tg.setVisibility(View.GONE);
                        break;
                    case "2":
                        bhg.setVisibility(View.GONE);
                        tg.setVisibility(View.GONE);
                        break;
                }
            }
        });
    }
}
